<?php

// +----------------------------------------------------------------------
// | MC PHP[基于ThinkPHP6.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://www.mingchangruanjian.com
// +----------------------------------------------------------------------
// | Author kobe [ jokerfei377@gmail.com ]
// +----------------------------------------------------------------------
// | 铭畅软件 技术部 出品
// +----------------------------------------------------------------------

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\common\service\ApiReturn;

/**
 * 用户资产
 */
class Assets extends Base
{
    /**
     * 用户资产信息
     * @author mitu
     * @date   2024-01-18
     * @param  array      $data [description]
     * @param  array      $user [description]
     * @return [type]           [description]
     */
    public function detail($data = [], $user = [])
    {
        $info = \app\admin\model\user\Assets::where('user_id', $user['id'])->find();
        return ApiReturn::r(1, $info, lang('common.successful'));
    }

    /**
     * 用户资产明细
     * @author mitu
     * @date   2024-01-18
     * @param  array      $data [description]
     * @param  array      $user [description]
     * @return [type]           [description]
     */
    public function lst($data = [], $user = [])
    {
        $where = [];
        $where[] = ['user_id', '=', $user['id']];
        if (isset($data['type']) && $data['type'] == 'income') {
            $where[] = ['change_money', '>=', 0];
        } else if (isset($data['type']) && $data['type'] == 'out') {
            $where[] = ['change_money', '<', 0];
        }
        if (isset($data['time']) && isset($data['time'])) {
            list($start, $end) = explode(' - ', $data['time']);
            $start .= ' 00:00:00';
            $end .= ' 23:59:59';
            $where[] = ["create_time", "between time", [$start, $end]];
        }
        $list = \app\admin\model\user\MoneyLog::where($where)
            ->order('id', 'desc')
            ->paginate();
        return ApiReturn::r(1, $list, lang('common.successful'));
    }

}
